﻿// Note: This source code includes code from the MVVM tutorial
// at http://msdn.microsoft.com/en-us/magazine/dd419663.aspx
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using WPF_GUI.Commanding;
using System.Windows.Input;
using System.Collections.ObjectModel;

namespace WPF_GUI.ViewModels
{
    class ManualRouteWindowViewModel : ChildWindowViewModel
    {
        private string _routeString;
        //private MainPageViewModel _parentViewModel;
        private ObservableCollection<string> _routeStrings = new ObservableCollection<string>();

        #region Fields

        // Commands
        RelayCommand _okButtonCommand;
        RelayCommand _cancelButtonCommand;

        #endregion // Fields
        
        public ManualRouteWindowViewModel(MainPageViewModel parentViewModel)
            : base (parentViewModel)
        {
            // Populate _routeStrings
            _routeStrings.Add("ASA222,6L/24R,AA,6R/24L");
            _routeStrings.Add("ASA222,6L/24R,AA,E");

            //_parentViewModel = parentViewModel;
            _routeString = "";
            CanClickOK = true;
            CanClickCancel = true;
        }
        
        #region Buttons

        #region Button Enablers

        private bool CanClickOK { get; set; }
        private bool CanClickCancel { get; set; }

        #endregion // Button Enablers

        #region Button Command Properties

        public ICommand ClickOKCommand
        {
            get
            {
                if (_okButtonCommand == null)
                {
                    _okButtonCommand = new RelayCommand(
                        param => this.ButtonOK_Click(),
                        param => this.CanClickOK
                        );
                }
                return _okButtonCommand;
            }
        }

        public ICommand ClickCancelCommand
        {
            get
            {
                if (_cancelButtonCommand == null)
                {
                    _cancelButtonCommand = new RelayCommand(
                        param => this.ButtonCancel_Click(),
                        param => this.CanClickCancel
                        );
                }
                return _cancelButtonCommand;
            }
        }

        #endregion // Button Command Properties

        #region Button Command Handlers

        public void ButtonOK_Click()
        {
            _parentViewModel.SaveManualRouteFromWindow(_routeString);
            //OnRequestClose(); // Request to close this window
        }

        public void ButtonCancel_Click()
        {
            OnRequestClose(); // Request to close this window
        }

        #endregion // Button Command Handlers

        #endregion // Buttons
        
        #region Properties

        public string RouteString
        {
            get
            {
                return _routeString;
            }

            set
            {
                if (_routeString != value)
                {
                    _routeString = value;
                    OnPropertyChanged("RouteString");
                }
            }
        }

        public ObservableCollection<string> RouteStrings
        {
            get
            {
                return _routeStrings;
            }

            set
            {
                if (_routeStrings != value)
                {
                    _routeStrings = value;
                }
            }
        }

        #endregion // Properties
    }
}
